import { reactive } from 'vue';
import useSearch from "./useSearch";
import useTableData from "./useTableData";

export default function useCompose() {
    // 查询表单
    const { searchForm, searchRefForm } = useSearch();

    // 列表数据
    const { 
        columns, 
        data, 
        dataTotal,
        scroll,
        bodyTitle,
        bodyTip,
        getTableData, 
        handeleTaskUserClick, 
        handleQueryDetail, 
        handleUpdateDetail, 
        changeStatusVisibile, 
        handleChangeStatus, 
        handleSubmitClick, 
        copyVisibile,
        handleCopyClick,
        handleSelect,
        total
    } = useTableData(searchForm);
    // 重置
    const reset = () => {
        searchRefForm.value.resetFields();
        searchForm.page = 1;
        searchForm.pageSize = 10;
        getTableData();
    };
    // 查询
    const search = () => {
        searchForm.page = 1;
        searchForm.department === '' && ( searchForm.department = undefined )
        searchForm.status === '' && ( searchForm.status = undefined )
        searchForm.uses === '' && ( searchForm.uses = undefined )
        searchForm.companyId === '' && ( searchForm.companyId = undefined )
        searchForm.label === '' && ( searchForm.label = undefined )
        searchForm.target === '' && ( searchForm.target = undefined )
        searchForm.annoUserId === '' && ( searchForm.annoUserId = undefined )
        searchForm.keyword && ( searchForm.keyword = searchForm.keyword.trim() );
        searchForm.status && ( searchForm.status = +searchForm.status );
        searchForm.annoUserId && ( searchForm.annoUserId = +searchForm.annoUserId );
        searchForm.companyId && ( searchForm.companyId = +searchForm.companyId );
        getTableData();
    };

    // 页码操作
    const handleSizeChange = (size: number) => {
        searchForm.page = size;
        getTableData();
    };

    // 每页条数操作
    const handlePageSizeChange = (pageSize: number) => {
        searchForm.pageSize = pageSize;
        getTableData();
    };

    return {
        searchForm,
        searchRefForm,
        search,
        reset,
        columns,
        data,
        dataTotal,
        scroll,
        bodyTitle,
        bodyTip,
        getTableData,
        handleSizeChange,
        handlePageSizeChange,
        handeleTaskUserClick,
        handleQueryDetail,
        handleUpdateDetail,
        changeStatusVisibile,
        handleChangeStatus,
        handleSubmitClick,
        copyVisibile,
        handleCopyClick,
        handleSelect,
        total
    }
}